import java.util.Arrays;
import java.util.PriorityQueue;

public class Main {


    //摆动序列
    public  int wiggleMaxlength(int[] nums){
        int n = nums.length;
        if (n<2) return n;

        int ret = 0,left = 0;
        for (int i = 0; i < n-1; i++) {
            int right = nums[i+1] - nums[i];
            if(right == 0) continue;
            if (left * right <= 0) ret++;
            left = right;
        }
        return ret +1;
    }

    //最大数
    public String largestNumber(int[] nums){
        // 优化：把所有的数转化成字符串
        int n = nums.length;
        String[] strs = new String[n];
        for(int i = 0; i < n; i++) strs[i] = "" + nums[i];

        Arrays.sort(strs, (a, b) ->
        {
            return (b + a).compareTo(a + b);
        });
        // 提取结果
        StringBuffer ret = new StringBuffer();
        for(String s : strs) ret.append(s);
        if(ret.charAt(0) == '0') return "0";
        return ret.toString();
    }


    //将数组和减半的最少操作次数
    public int halveArray(int[] nums){
        //创建大根堆
        PriorityQueue<Double> heap = new PriorityQueue<>((a,b)->b.compareTo(a));

        double sum = 0.0;
        for (int x:nums) {
            heap.offer((double) x);
            sum+=x;
        }
        sum/=2.0;

        int count = 0;
        while(sum>0){
            double t = heap.poll()/2.0;
            sum-=t;
            count++;
            heap.offer(t);
        }
        return count;
    }

    //柠檬水找零
    public boolean lemoadeChange(int[] bills){
        int five = 0, ten = 0;
        for (int x :bills) {
            if (x == 5){
                five++;
            }else if(x == 10){
                if (five == 0) return false;
                five--;
                ten++;
            }else{
                if (five!=0 && ten!=0){
                    five--;
                    ten--;
                }else if(five>=3){
                    five -=3;
                }else return false;
            }
        }
        return true;
    }


    public static void main(String[] args) {
        System.out.println("Hello world!");
    }
}